import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'; // 引入node的path模块
// 引入viteMockServe
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    viteMockServe({
      mockPath: "./mock/"
    }),
  ],
  base: './',
  resolve: {
    // 设置别名路径
    alias: {
      '@': path.resolve(__dirname, 'src'),
      'comp': path.resolve(__dirname, 'src/components')
    },
  },
  server: {
    open: true,// 运行直接打开
    port: '8080',// 更改默认端口
    hmr: true,// 开启热更新
    proxy: { // 代理
      '/api': {
        target: 'http://localhost:1111',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    },
  },
  build: {
    outDir: 'fengMusic',//打包出来的文件夹名字，默认为dist
    assetsDir: './',// 打包指定输出路径
    terserOptions: {
      // 生产环境一出console / debuger
      compress: {
        drop_console: true,
        drop_debugger: true,
      }
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve("src/assets/css/common/config.less")}";`
        },
        javascriptEnabled: true,
      }
    }
  }
})
